{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 首先 import 必要的模块\n",
    "import pandas as pd \n",
    "import numpy as np\n",
    "\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pregnants</th>\n",
       "      <th>Plasma_glucose_concentration</th>\n",
       "      <th>blood_pressure</th>\n",
       "      <th>Triceps_skin_fold_thickness</th>\n",
       "      <th>serum_insulin</th>\n",
       "      <th>BMI</th>\n",
       "      <th>Diabetes_pedigree_function</th>\n",
       "      <th>Age</th>\n",
       "      <th>Target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.639947</td>\n",
       "      <td>0.866045</td>\n",
       "      <td>-0.031990</td>\n",
       "      <td>0.670643</td>\n",
       "      <td>-0.181541</td>\n",
       "      <td>0.166619</td>\n",
       "      <td>0.468492</td>\n",
       "      <td>1.425995</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.844885</td>\n",
       "      <td>-1.205066</td>\n",
       "      <td>-0.528319</td>\n",
       "      <td>-0.012301</td>\n",
       "      <td>-0.181541</td>\n",
       "      <td>-0.852200</td>\n",
       "      <td>-0.365061</td>\n",
       "      <td>-0.190672</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.233880</td>\n",
       "      <td>2.016662</td>\n",
       "      <td>-0.693761</td>\n",
       "      <td>-0.012301</td>\n",
       "      <td>-0.181541</td>\n",
       "      <td>-1.332500</td>\n",
       "      <td>0.604397</td>\n",
       "      <td>-0.105584</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.844885</td>\n",
       "      <td>-1.073567</td>\n",
       "      <td>-0.528319</td>\n",
       "      <td>-0.695245</td>\n",
       "      <td>-0.540642</td>\n",
       "      <td>-0.633881</td>\n",
       "      <td>-0.920763</td>\n",
       "      <td>-1.041549</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-1.141852</td>\n",
       "      <td>0.504422</td>\n",
       "      <td>-2.679076</td>\n",
       "      <td>0.670643</td>\n",
       "      <td>0.316566</td>\n",
       "      <td>1.549303</td>\n",
       "      <td>5.484909</td>\n",
       "      <td>-0.020496</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   pregnants  Plasma_glucose_concentration  blood_pressure  \\\n",
       "0   0.639947                      0.866045       -0.031990   \n",
       "1  -0.844885                     -1.205066       -0.528319   \n",
       "2   1.233880                      2.016662       -0.693761   \n",
       "3  -0.844885                     -1.073567       -0.528319   \n",
       "4  -1.141852                      0.504422       -2.679076   \n",
       "\n",
       "   Triceps_skin_fold_thickness  serum_insulin       BMI  \\\n",
       "0                     0.670643      -0.181541  0.166619   \n",
       "1                    -0.012301      -0.181541 -0.852200   \n",
       "2                    -0.012301      -0.181541 -1.332500   \n",
       "3                    -0.695245      -0.540642 -0.633881   \n",
       "4                     0.670643       0.316566  1.549303   \n",
       "\n",
       "   Diabetes_pedigree_function       Age  Target  \n",
       "0                    0.468492  1.425995       1  \n",
       "1                   -0.365061 -0.190672       0  \n",
       "2                    0.604397 -0.105584       1  \n",
       "3                   -0.920763 -1.041549       0  \n",
       "4                    5.484909 -0.020496       1  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train = pd.read_csv(\"FE_pima_indians_diabetes.csv\")\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y_train = train['Target']   \n",
    "X_train = train.drop([\"Target\"], axis=1)\n",
    "\n",
    "#保存特征名字以备后用（可视化）\n",
    "feat_names = X_train.columns "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# \t采用5折交叉验证的log似然损失和正确率（不包含调优）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "logloss of each fold is:  [ 0.48797856  0.53011593  0.4562292   0.422546    0.48392885]\n",
      "cv logloss is: 0.476159709444\n"
     ]
    }
   ],
   "source": [
    "# 交叉验证用于评估模型性能和进行参数调优（模型选择）\n",
    "#分类任务中交叉验证缺省是采用StratifiedKFold,默认是分层抽样\n",
    "#作业要求，采用5折交叉验证\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "lr = LogisticRegression()\n",
    "\n",
    "from sklearn.model_selection import cross_val_score #这个库主要为了得到分数\n",
    "loss = cross_val_score(lr, X_train, y_train, cv=5, scoring='neg_log_loss')\n",
    "#%timeit loss_sparse = cross_val_score(lr, X_train_sparse, y_train, cv=3, scoring='neg_log_loss')\n",
    "print 'logloss of each fold is: ',-loss\n",
    "print'cv logloss is:', -loss.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "accuracy of each fold is:  [ 0.75974026  0.74025974  0.78571429  0.79738562  0.77124183]\n",
      "cv accuracy is: 0.770868347339\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import cross_val_score #这个库主要为了得到分数\n",
    "loss = cross_val_score(lr, X_train, y_train, cv=5, scoring='accuracy')\n",
    "#%timeit loss_sparse = cross_val_score(lr, X_train_sparse, y_train, cv=3, scoring='neg_log_loss')\n",
    "print 'accuracy of each fold is: ',loss\n",
    "print'cv accuracy is:', loss.mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 采用5折交叉验证的log似然损失的超参数调优"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "    # 使用GridSearchCV对log_loss优化的过程和结果如下："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#为了比较GridSearchCV和LogisticRegressionCV，两者用相同的交叉验证数据分割\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "fold = StratifiedKFold(n_splits=5, shuffle=True, random_state=777)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=StratifiedKFold(n_splits=5, random_state=777, shuffle=True),\n",
       "       error_score='raise',\n",
       "       estimator=LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n",
       "          intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,\n",
       "          penalty='l2', random_state=None, solver='liblinear', tol=0.0001,\n",
       "          verbose=0, warm_start=False),\n",
       "       fit_params=None, iid=True, n_jobs=-1,\n",
       "       param_grid={'penalty': ['l1', 'l2'], 'C': [0.001, 0.01, 0.1, 1, 10, 100, 1000]},\n",
       "       pre_dispatch='2*n_jobs', refit=True, return_train_score=True,\n",
       "       scoring='neg_log_loss', verbose=0)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.model_selection import GridSearchCV #超参数调优的库\n",
    "from sklearn.linear_model import LogisticRegression #调优用的算法库\n",
    "\n",
    "#需要调优的参数\n",
    "# 请尝试将L1正则和L2正则分开，并配合合适的优化求解算法（slover）\n",
    "#tuned_parameters = {'penalty':['l1','l2'],\n",
    "#                   'C': [0.001, 0.01, 0.1, 1, 10, 100, 1000]\n",
    "#                   }\n",
    "penaltys = ['l1','l2']\n",
    "Cs = [0.001, 0.01, 0.1, 1, 10, 100, 1000]\n",
    "tuned_parameters = dict(penalty = penaltys, C = Cs)\n",
    "\n",
    "lr_penalty= LogisticRegression(solver='liblinear')\n",
    "grid= GridSearchCV(lr_penalty, tuned_parameters,cv=fold, scoring='neg_log_loss',n_jobs = -1,)#负log似然损失\n",
    "grid.fit(X_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.474821277768\n",
      "{'penalty': 'l1', 'C': 1}\n"
     ]
    }
   ],
   "source": [
    "# examine the best model\n",
    "print(-grid.best_score_)\n",
    "print(grid.best_params_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8VOW9x/HPb2aysIQ9bAkIYqjsSyKCCxVRwaWoQFTq\ndWsV22rtcmtrb+uG3Zdbe1taRdSqVRHBhYKtC4K4IYRVAqKAC2GTRfYlyzz3jxk0hpCZJDM5M5Pv\n++V5ZebMc+Z8D2p+nOV5HnPOISIiUhOf1wFERCTxqViIiEhEKhYiIhKRioWIiESkYiEiIhGpWIiI\nSEQqFiIiEpGKhYiIRKRiISIiEQW8DhAr7dq1c926dfM6hohIUlmyZMkO51x2pHZxLRZmNhr4M+AH\npjrnflPl8z8B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QBOBX7unAsChEennRNu+1y4vUhC0GmuSN2MBQYCAwj1aF5sZguA04FuQD+gPaHhrx8K\nb3M68GT4dR9CvdErjvP9q4BT4pJcpA50ZiFSN2cAT4ZH/NwGvEbol/sZwNPOuaBzbiswr9I2nYDt\n0Xx5uIiUhifnEfGcioVI3VQ3/HhN6wEOAZnh18XAADOr6f/BDOBwHbKJxJyKhUjdLAAuD088kw0M\nBxYRmtZyXPjeRQdCA+8dtQY4CcA5tx4oAu4Oj4KKmeUdncPDzNoC251zZQ11QCI1UbEQqZtngZXA\nCuBV4Mfhy04zCc1jsYrQvOHvAHvC28zhy8XjeqAjsM7M3gUe4Iv5LkYASTcKqqQujTorEmNm1tw5\ntz98drAION05tzU838C88Pvj3dg++h3PAD9N4vnHJcXoaSiR2JsdnpAmHbgnfMaBc+6Qmd1JaB7u\nT463cXiipOdUKCSR6MxCREQi0j0LERGJSMVCREQiUrEQEZGIVCxERCQiFQsREYlIxUJERCL6f5gB\nbsHdOtnLAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xf2fe358>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot CV误差曲线\n",
    "test_means = grid.cv_results_[ 'mean_test_score' ]\n",
    "test_stds = grid.cv_results_[ 'std_test_score' ]\n",
    "train_means = grid.cv_results_[ 'mean_train_score' ]\n",
    "train_stds = grid.cv_results_[ 'std_train_score' ]\n",
    "\n",
    "# plot results\n",
    "n_Cs = len(Cs)\n",
    "number_penaltys = len(penaltys)\n",
    "test_scores = np.array(test_means).reshape(n_Cs,number_penaltys)\n",
    "train_scores = np.array(train_means).reshape(n_Cs,number_penaltys)\n",
    "test_stds = np.array(test_stds).reshape(n_Cs,number_penaltys)\n",
    "train_stds = np.array(train_stds).reshape(n_Cs,number_penaltys)\n",
    "\n",
    "x_axis = np.log10(Cs)\n",
    "for i, value in enumerate(penaltys):\n",
    "    #pyplot.plot(log(Cs), test_scores[i], label= 'penalty:'   + str(value))\n",
    "    plt.errorbar(x_axis, -test_scores[:,i], yerr=test_stds[:,i] ,label = penaltys[i] +' Test')\n",
    "    #plt.errorbar(x_axis, -train_scores[:,i], yerr=train_stds[:,i] ,label = penaltys[i] +' Train')\n",
    "    \n",
    "plt.legend()\n",
    "plt.xlabel( 'log(C)' )                                                                                                      \n",
    "plt.ylabel( 'logloss' )\n",
    "plt.savefig('LogisticGridSearchCV_C.png' )\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "lr_best = grid.best_estimator_"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "    # 使用LogisticRegressionCV的过程和结果如下："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LogisticRegressionCV(Cs=[0.001, 0.01, 0.1, 1, 10, 100, 1000],\n",
       "           class_weight=None,\n",
       "           cv=StratifiedKFold(n_splits=5, random_state=777, shuffle=True),\n",
       "           dual=False, fit_intercept=True, intercept_scaling=1.0,\n",
       "           max_iter=100, multi_class='ovr', n_jobs=-1, penalty='l1',\n",
       "           random_state=None, refit=True, scoring='neg_log_loss',\n",
       "           solver='liblinear', tol=0.0001, verbose=0)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import LogisticRegressionCV\n",
    "\n",
    "Cs = [1e-3, 1e-2, 1e-1, 1, 10, 100, 1000]\n",
    "#nCs = 9  #Cs values are chosen in a logarithmic scale between 1e-4 and 1e4.\n",
    "\n",
    "# 大量样本（6W+）、高维度（93），L1正则 --> 可选用saga优化求解器(0.19版本新功能)\n",
    "#LogisticRegressionCV比GridSearchCV快\n",
    "\n",
    "##  multi_class:分类方式选择参数，有\"ovr(默认)\"和\"multinomial\"两个值可选择，在二元逻辑回归中无区别\n",
    "##  cv:几折交叉验证\n",
    "##  solver:优化算法选择参数，当penalty为\"l1\"时，参数只能是\"liblinear(坐标轴下降法)\"\n",
    "##  \"lbfgs\"和\"cg\"都是关于目标函数的二阶泰勒展开\n",
    "##  当penalty为\"l2\"时，参数可以是\"lbfgs(拟牛顿法)\",\"newton_cg(牛顿法变种)\",\"seg(minibactch随机平均梯度下降)\"\n",
    "##  维度<10000时，选择\"lbfgs\"法，维度>10000时，选择\"cs\"法比较好，显卡计算的时候，lbfgs\"和\"cs\"都比\"seg\"快\n",
    "##  penalty:正则化选择参数，用于解决过拟合，可选\"l1\",\"l2\"\n",
    "\n",
    "lrcv_L1 = LogisticRegressionCV(Cs=Cs, cv = fold, scoring='neg_log_loss', penalty='l1', solver='liblinear', multi_class='ovr',n_jobs=-1)\n",
    "lrcv_L1.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-0.69314718 -0.6355833  -0.47516525 -0.47672737 -0.47722566 -0.47732288\n",
      "  -0.47733407]\n",
      " [-0.69314718 -0.63351954 -0.47338828 -0.47434004 -0.47546105 -0.4755904\n",
      "  -0.4756008 ]\n",
      " [-0.69314718 -0.63314679 -0.47259992 -0.46550388 -0.4652115  -0.46518755\n",
      "  -0.46519043]\n",
      " [-0.69314718 -0.63283612 -0.46476213 -0.45630189 -0.45587616 -0.45583477\n",
      "  -0.45583927]\n",
      " [-0.69314718 -0.64060504 -0.49750361 -0.50127988 -0.50276385 -0.50292774\n",
      "  -0.50294052]]\n"
     ]
    }
   ],
   "source": [
    "print(lrcv_L1.scores_[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUe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5MN94dz8FuA4YFgw6+HvgikgKFemAwkKkCyzp\nB8EYVivN7IpgfczM/is4UnjKzBaZ2WXBZp8GFgTtTgBmAN9w9zaAYHTap4O284P2IllBh7kiXfMp\nIAFMJXlH81IzewE4CxgLnAoMJzn89f3BNmcBjwSvTyF5N3rrET7/deCMUCoX6QIdWYh0zdnAI8GI\nn1uAP5D8cT8b+KW7t7n7ZuC5lG1GAdsy+fAgRJqCyXlEIqewEOmajoYfP9p6gENAWfB6FTDVzI72\nd7AUaOhCbSI9TmEh0jUvAFcEE8+UA+cAr5Cc1vLS4NrFCJID7x22BjgRwN3fBmqAfwpGQcXMxh+e\nw8PMhgLb3L25t3ZI5GgUFiJd8wSwAqgFngX+V3Da6XGS81i8TnLe8CXAnmCbp3l/eHwOGAnUmdlK\n4F7+Ot9X/Q5XAAAAhElEQVTFuUDOjYIq+Uujzor0MDPr5+77g6ODV4Cz3H1zMN/Ac8HykS5sH/6M\nXwG35fD845Jn1BtKpOc9FUxIUwJ8KzjiwN0PmdkdJOfhfu9IGwcTJc1XUEg20ZGFiIikpWsWIiKS\nlsJCRETSUliIiEhaCgsREUlLYSEiImkpLEREJK3/D0+07J+90aFAAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x75e0dd8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# scores_：dict with classes as the keys, and the values as the grid of scores obtained during cross-validating each fold,\n",
    "# Each dict value has shape (n_folds, len(Cs))\n",
    "Cs = [1e-3, 1e-2, 1e-1, 1, 10, 100, 1000]\n",
    "n_Cs = len(Cs)\n",
    "n_classes = 1\n",
    "scores =  np.zeros((n_classes,n_Cs))\n",
    "\n",
    "for j in range(n_classes):\n",
    "        scores[j][:] = np.mean(lrcv_L1.scores_[j+1],axis = 0)\n",
    "    \n",
    "logloss_mean = -np.mean(scores, axis = 0)\n",
    "plt.plot(np.log10(Cs), logloss_mean.reshape(n_Cs,1)) \n",
    "#plt(np.log10(reg.Cs)*np.ones(3), [0.28, 0.29, 0.30])\n",
    "plt.xlabel('log(C)')\n",
    "plt.ylabel('logloss')\n",
    "plt.show()\n",
    "\n",
    "#print ('C is:',lr_cv.C_)  #对多类分类问题，每个类别的分类器有一个C"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.69314718,  0.63513816,  0.47668384,  0.47483061,  0.47530764,\n",
       "        0.47537267,  0.47538102])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logloss_mean"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 0.47483061213583666)\n"
     ]
    }
   ],
   "source": [
    "best_C = np.argmin(logloss_mean)\n",
    "best_score = np.min(logloss_mean)\n",
    "print (Cs[best_C], best_score)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "得到的结果虽然与Gridcv有区别但是区别不大"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# GridSearchCV对正确率超参数优化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=3, error_score='raise',\n",
       "       estimator=LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n",
       "          intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,\n",
       "          penalty='l2', random_state=None, solver='liblinear', tol=0.0001,\n",
       "          verbose=0, warm_start=False),\n",
       "       fit_params=None, iid=True, n_jobs=1,\n",
       "       param_grid={'penalty': ['l1', 'l2'], 'C': [0.1, 1, 10, 100, 1000]},\n",
       "       pre_dispatch='2*n_jobs', refit=True, return_train_score=True,\n",
       "       scoring='accuracy', verbose=0)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.model_selection import GridSearchCV\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "\n",
    "#需要调优的参数\n",
    "# 请尝试将L1正则和L2正则分开，并配合合适的优化求解算法（slover）\n",
    "#tuned_parameters = {'penalty':['l1','l2'],\n",
    "#                   'C': [0.001, 0.01, 0.1, 1, 10, 100, 1000]\n",
    "#                   }\n",
    "penaltys = ['l1','l2']\n",
    "\n",
    "#训练数据多，C可以大一点（更多相信数据）\n",
    "Cs = [ 0.1, 1, 10, 100, 1000]\n",
    "tuned_parameters = dict(penalty = penaltys, C = Cs)\n",
    "\n",
    "lr_penalty= LogisticRegression()\n",
    "grid= GridSearchCV(lr_penalty, tuned_parameters,cv=3, scoring='accuracy')\n",
    "grid.fit(X_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.772135416667\n",
      "{'penalty': 'l1', 'C': 1}\n"
     ]
    }
   ],
   "source": [
    "# examine the best model\n",
    "print(grid.best_score_)\n",
    "print(grid.best_params_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZoAAAEKCAYAAAArYJMgAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt8FdW5//HPE24BuQWSQLhGIYgiQjUiiCI3C15aUEGx\nWtGK1LbW1t+vVnrssdW2Sk9bbfuzVZFWscejWC2KCHKrAirqiQgKogERNRIhRC4iRIE8vz9mghvY\nSXYuk53A9/167deeWbNm5pmB5MmstWbG3B0REZGopCQ7ABERObIp0YiISKSUaEREJFJKNCIiEikl\nGhERiZQSjYiIREqJRkREIqVEIyIikVKiERGRSDVOdgD1QXp6umdnZyc7DBGRBuX111/f6u4ZldVT\nogGys7PJy8tLdhgiIg2KmX2QSD01nYmISKSUaEREJFJKNCIiEin10YiIxNi7dy8FBQWUlJQkO5R6\nIzU1lS5dutCkSZNqra9EIyISo6CggFatWpGdnY2ZJTucpHN3iouLKSgo4Nhjj63WNtR0JiISo6Sk\nhPbt2yvJhMyM9u3b1+gKT4lGROQQSjIHq+n5UKIREamhS+9fzqX3L092GPWWEk0N6D+XiEShZcuW\nB6ZHjx5N27ZtueCCC+LW/cEPfkD//v058cQTad68Of3796d///488cQTVdrnihUreO6552oUd3k0\nGEBEpB676aab2L17N/fff3/c5X/5y18A2LhxIxdccAErV66s1n5WrFjB6tWrGT16dLVjLY+uaERE\n6rERI0bQqlWraq27bt06Ro0axamnnsqQIUPIz88H4LHHHuOkk06iX79+DBs2jD179nD77bfzyCOP\nVOtqqDK6ohERKcdtz6zh7U07K633dmFQJ5Gm9BM7teYX3+hT49gSMXnyZKZPn06PHj146aWXuP76\n61mwYAG33XYbL7zwAh06dGD79u00b96cW2+9ldWrV/PHP/6x1uNISqIxs3bATCAb2Ahc4u7bDqkz\nDLg7pqg3MMHdnzKzh4CzgR3hsqvcfaUFQyP+BJwH7A7LV0R4KCIi9dL27dt55ZVXuPjiiw+U7du3\nD4DBgwdz5ZVXMn78eC666KLIY0nWFc0UYLG7TzWzKeH8zbEV3P15oD8cSEzrgQUxVW5y90Ov784F\ncsLP6cC94beISJUleuVRdiUz87uDogynStyd9PT0uH02DzzwAK+++ipz5syhX79+vPnmm5HGkqw+\nmjHAjHB6BjC2kvrjgHnuvjuB7T7sgVeAtmaWVbNQRUQanrS0NLKyspg1axYApaWlrFq1CoANGzYw\ncOBAfvWrX5GWlsbHH39Mq1at+OyzzyKJJVmJpoO7FwKE35mV1J8APHpI2W/M7E0zu9vMmoVlnYGP\nYuoUhGWHMbPJZpZnZnlFRUVVPwIRkTpw1llnMX78eBYvXkyXLl2YP39+wus+9thj3HffffTr148+\nffowZ84cAG688Ub69u1L3759GTlyJCeddBLDhw9n1apVfO1rX2s4gwHMbBHQ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DCH6nFFe8Vq3s14C/\nAWvd/a5yqtXpOUskpiSer4zwSgYzaw6MBN45pFp0P5N1PfqhoX+ACwky/xfAZmB+WN4JmBtT7zyC\nUSfvETS5RR1Xe2AxsC78bheW5wLTw+kzgLcIRlu9BVwTYTyHHT9wO/DNcDoV+CewHngNOK6O/v0q\ni+tOYE14jp4HetdRXI8ChcDe8P/XNcB1wHXhcgP+Esb9FuWMeExCXNfHnK9XgDPqKK4zCZp13gRW\nhp/zknnOEowpWefrZOCNMLbVwK1heZ38TOrJACIiEik1nYmISKSUaEREJFJKNCIiEiklGhERiZQS\njYiIREqJRqSOmNmuymtVuP4T4RMdMLOWZna/mb0XPo13qZmdbmZNw2ndjC31hhKNSAMQPhOrkbtv\nCIumE9y1nePufQieOp3uwcNCFwOXJiVQkTiUaETqWHin+u/MbLWZvWVml4blKeEjSdaY2Rwzm2tm\n48LVLid82oOZ9QBOB37u7qUQPFLI3Z8N6z4V1hepF3R5LVL3LgL6A/2AdOB/zWwpwSOBsoG+BE/f\nXgv8PVxnMMFd+gB9gJUePCQxntXAaZFELlINuqIRqXtnEjwher+7bwaWECSGM4F/unupu39C8Aic\nMllAUSIbDxPQl2bWqpbjFqkWJRqRulfey6QqesnUHoJnUUHwrKx+ZlbRz28zoKQasYnUOiUakbq3\nFLg0fBFVBsHrkl8DXiR46VqKmXUgeO1vmbVATwAP3h+UB9wW8yTgHDMbE063B4rcfW9dHZBIRZRo\nROreLIKn6K4C/g38NGwqe5LgCcmrgfsJ3s64I1znWQ5OPJMIXoK33szeInh3Ttm7VoYBc6M9BJHE\n6enNIvWImbX04O2L7Qmucga7+yfhO0SeD+fLGwRQto1/AT9z93frIGSRSmnUmUj9Mid8QVVT4Ffh\nlQ7uvsfMfkHwXvcPy1s5fKHbU0oyUp/oikZERCKlPhoREYmUEo2IiERKiUZERCKlRCMiIpFSohER\nkUgp0YiISKT+P2y6xpFpZxT4AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xf38d208>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot CV误差曲线\n",
    "test_means = grid.cv_results_[ 'mean_test_score' ]\n",
    "test_stds = grid.cv_results_[ 'std_test_score' ]\n",
    "train_means = grid.cv_results_[ 'mean_train_score' ]\n",
    "train_stds = grid.cv_results_[ 'std_train_score' ]\n",
    "\n",
    "\n",
    "# plot results\n",
    "n_Cs = len(Cs)\n",
    "number_penaltys = len(penaltys)\n",
    "test_scores = np.array(test_means).reshape(n_Cs,number_penaltys)\n",
    "train_scores = np.array(train_means).reshape(n_Cs,number_penaltys)\n",
    "test_stds = np.array(test_stds).reshape(n_Cs,number_penaltys)\n",
    "train_stds = np.array(train_stds).reshape(n_Cs,number_penaltys)\n",
    "\n",
    "x_axis = np.log10(Cs)\n",
    "for i, value in enumerate(penaltys):\n",
    "    #pyplot.plot(log(Cs), test_scores[i], label= 'penalty:'   + str(value))\n",
    "    plt.errorbar(x_axis, -test_scores[:,i], yerr=test_stds[:,i] ,label = penaltys[i] +' Test')\n",
    "    #plt.errorbar(x_axis, -train_scores[:,i], yerr=train_stds[:,i] ,label = penaltys[i] +' Train')\n",
    "    \n",
    "plt.legend()\n",
    "plt.xlabel( 'log(C)' )                                                                                                      \n",
    "plt.ylabel( 'accuracy' )\n",
    "\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
